Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade original targets #2942

Merged

Conversation

peterebden
Copy link
Collaborator

@peterebden peterebden commented Nov 2, 2023

We've found cases where this can be notably slow when piping very large numbers of targets into plz. The code there is pretty old - when it was written we didn't have repos with hundreds of thousands of targets or remote execution with hundreds of workers, so we never really noticed.

This upgrades the implementation to be more efficient rather than running over a huge slice again and again.

I've tested using the profiler locally and things look much more sensible after this (i.e. not all the time is going into OriginalTarget functions any more)

// Less returns true if this build label would sort less than another one.
func (label BuildLabel) Less(other BuildLabel) bool {
if label.PackageName == other.PackageName {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm restructuring this a bit but also it was wrong for ages because it didn't look at subrepos.

@@ -59,7 +59,8 @@ func TestExpandVisibleOriginalTargets(t *testing.T) {

func TestExpandOriginalSubLabels(t *testing.T) {
state := NewDefaultBuildState()
state.AddOriginalTarget(BuildLabel{PackageName: "src/core", Name: "..."}, true)
Copy link
Collaborator Author

@peterebden peterebden Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever actually needed to support this. The new implementation just panics but things like plz test //... are still fine - those are turned into a sequence of :all targets elsewhere.

Copy link
Member

@Tatskaari Tatskaari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Maybe we can try this out.

ChangeLog Outdated
@@ -11,6 +11,7 @@ Version 17.4.0
* Add all commit date formats to supported git_show() format verbs (#2930)
* Fix reduce builtin (#2925)
* Fix issue with completing idents in the language server (#2917)
* Improve performance when a large number of input targets are supplied (#2942)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is a bit wonk here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M-x untabify

}
return false
return state.progress.originalTargets.Match(target.Label) && state.ShouldInclude(target)
Copy link
Member

@Tatskaari Tatskaari Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic isn't quite right. I think what we want is:

func (state *BuildState) isOriginalTarget(target *BuildTarget, exactOnly bool) bool {
    allTargetsMatch, exact := state.progress.originalTargets.Match(target.Label)
    return exact || (!exactOnly && allTargetsMatch && state.ShouldInclude(target)) 
}

Currently if I have a test with labels = ["manual"] and I match it exactly i.e. plz test //tests:manual, then it will be excluded because it's not an exact match.

Copy link
Member

@Tatskaari Tatskaari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow okay slowpoke

@peterebden peterebden merged commit e1028b9 into thought-machine:master Nov 3, 2023
5 checks passed
@peterebden peterebden deleted the upgrade-original-targets branch November 3, 2023 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants